#include "mainwindow.h"
#include "./ui_mainwindow.h"

#include <QDebug>
#include <QGraphicsView>
#include <QHBoxLayout>
#include "ElaContentDialog.h"
#include "ElaDockWidget.h"
#include "ElaEventBus.h"
#include "ElaLog.h"
#include "ElaMenu.h"
#include "ElaMenuBar.h"
#include "ElaProgressBar.h"
#include "ElaStatusBar.h"
#include "ElaText.h"
#include "ElaTheme.h"
#include "ElaToolBar.h"
#include "ElaToolButton.h"
#include "ElaWindow.h"
#include <QMouseEvent>
#ifdef Q_OS_WIN
#include "ElaApplication.h"
#include <QTimer>
#endif

#include "page/t_home.h"
#include "page/T_Setting.h"
#include "page/T_Graphics.h"

MainWindow::MainWindow(QWidget *parent)
    : ElaWindow(parent)
{
    resize(1200, 740);
    setWindowTitle("智能控制中心");
    setUserInfoCardPixmap(QPixmap(":/include/Image/Cirno.jpg"));
    setUserInfoCardTitle("赵司晨");
    setUserInfoCardSubTitle("your@gmail.com");
    ElaText* centralStack = new ElaText("这是一个主窗口堆栈页面", this);
    QFont font = centralStack->font();
    font.setPixelSize(32);
    centralStack->setFont(font);
    centralStack->setAlignment(Qt::AlignCenter);
    addCentralWidget(centralStack);

    _cardPage = new T_Card(this);
    addPageNode("HOME", _cardPage, ElaIconType::House);

    _settingPage = new T_Setting(this);
    addPageNode("Setting", _settingPage,ElaIconType::GearComplex);

    _graphicsPage = new T_Graphics(this);
    addPageNode("Security", _graphicsPage, 1, ElaIconType::Paintbrush);

    connect(_settingPage, &T_Setting::envDataChanged, _cardPage, &T_Card::updateEnv);

    // 拦截默认关闭事件
    _closeDialog = new ElaContentDialog(this);
    connect(_closeDialog, &ElaContentDialog::rightButtonClicked, this, &MainWindow::closeWindow);
    connect(_closeDialog, &ElaContentDialog::middleButtonClicked, this, [=]() {
        _closeDialog->close();
        showMinimized();
    });
    this->setIsDefaultClosed(false);
    connect(this, &MainWindow::closeButtonClicked, this, [=]() {
        _closeDialog->exec();
    });

    moveToCenter();
}

MainWindow::~MainWindow()
{
    delete ui;
}
